﻿using Chat_IService;
using Chat_Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Chat_Service
{
    public class LarTalkListService : BaseService<LarTalkList>, ILarTalkListService
    {
        /// <summary>
        /// 查询聊天列表
        /// </summary>
        public async Task<List<LarTalkList>> GetTalkListAsync(Expression<Func<LarTalkList, bool>> whereExpression)
        {
            var list = await Context.Queryable<LarTalkList>()
              .Mapper(it => it.LarGroup, it => it.ReceiverId)
              //.Mapper(it =>
              //{
              //    it.LarGroup = it.TalkType == 2 ? it.LarGroup : null;
              //})
              .Mapper(it => it.LarUsers, it => it.ReceiverId)
              //.Mapper(it =>
              //{
              //    it.LarUsers = it.TalkType == 1 ? it.LarUsers : null;
              //})
              .Mapper(it => it.LarTalkRecordsList, it => it.LarTalkRecordsList.First().ReceiverId, it => it.UserId)
            .Where(whereExpression)
            .ToListAsync();
            return list;
        }
    }
}